home *** CD-ROM | disk | FTP | other *** search
/ PC Open 101 / PC Open 101 CD 1.bin / CD1 / INTERNET / EMAIL / pop file / setup.exe / Platform / MSWin32.pm
Encoding:
Perl POD Document  |  2004-09-21  |  5.0 KB  |  170 lines

  1. # POPFILE LOADABLE MODULE
  2. package Platform::MSWin32;
  3.  
  4. use POPFile::Module;
  5. @ISA = ("POPFile::Module");
  6.  
  7. #----------------------------------------------------------------------------
  8. #
  9. # This module handles POPFile specifics on Windows
  10. #
  11. # Copyright (c) 2001-2004 John Graham-Cumming
  12. #
  13. #   This file is part of POPFile
  14. #
  15. #   POPFile is free software; you can redistribute it and/or modify
  16. #   it under the terms of the GNU General Public License as published by
  17. #   the Free Software Foundation; either version 2 of the License, or
  18. #   (at your option) any later version.
  19. #
  20. #   POPFile is distributed in the hope that it will be useful,
  21. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. #   GNU General Public License for more details.
  24. #
  25. #   You should have received a copy of the GNU General Public License
  26. #   along with POPFile; if not, write to the Free Software
  27. #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. #
  29. #----------------------------------------------------------------------------
  30.  
  31. use strict;
  32. use warnings;
  33. use locale;
  34.  
  35. #----------------------------------------------------------------------------
  36. # new
  37. #
  38. #   Class new() function
  39. #----------------------------------------------------------------------------
  40. sub new
  41. {
  42.     my $type = shift;
  43.     my $class = ref($type) || $type;
  44.     my $self = POPFile::Module->new();
  45.  
  46.     bless $self, $type;
  47.  
  48.     $self->name( 'windows' );
  49.  
  50.     return $self;
  51. }
  52.  
  53. # ---------------------------------------------------------------------------------------------
  54. #
  55. # initialize
  56. #
  57. # Called when we are are being set up but before starting
  58. #
  59. # ---------------------------------------------------------------------------------------------
  60. sub initialize
  61. {
  62.     my ( $self ) = @_;
  63.  
  64.     $self->config_( 'trayicon', 1 );
  65.     $self->config_( 'console',  0 );
  66.  
  67.     return 1;
  68. }
  69.  
  70. # ---------------------------------------------------------------------------------------------
  71. #
  72. # start
  73. #
  74. # Called when all configuration information has been loaded from disk.
  75. #
  76. # The method should return 1 to indicate that it started correctly, if
  77. # it returns 0 then POPFile will abort loading immediately, returns 2
  78. # if everything OK but this module does not want to continue to be
  79. # used.
  80. #
  81. # ---------------------------------------------------------------------------------------------
  82.  
  83. sub start
  84. {
  85.     my ( $self ) = @_;
  86.  
  87.     $self->register_configuration_item_( 'configuration',
  88.                                          'windows_trayicon_and_console',
  89.                                          'windows-configuration.thtml',
  90.                                          $self );
  91.  
  92.     # Now try to cleanup a mess that PerlApp/PerlTray might have left
  93.     # behind in the $TEMP.  For some reason even though we build with
  94.     # --clean it leaves behind empty directories in the TEMP directory
  95.     # in the form $TEMP/pdk-USER-PID
  96.     #
  97.     # We try to delete everything that is in that form but does not have 
  98.     # our PID
  99.  
  100.     my $pdk = $ENV{TEMP} . "/pdk-" . Win32::LoginName() . "-*";
  101.     $pdk =~ s/ /?/g;
  102.  
  103.     my @temp = glob $pdk;
  104.  
  105.     foreach my $dir (@temp) {
  106.         if ( $dir =~ /pdk\-.+\-(\d+)$/ ) {
  107.                if ( $$ != $1 ) {
  108.                 rmdir $dir;
  109.             }
  110.         }
  111.     }
  112.  
  113.     return $self->SUPER::start();
  114. }
  115.  
  116. # ---------------------------------------------------------------------------------------------
  117. #
  118. # configure_item
  119. #
  120. #    $name            Name of this item
  121. #    $templ           The loaded template that was passed as a parameter
  122. #                     when registering
  123. #    $language        Current language
  124. #
  125. # ---------------------------------------------------------------------------------------------
  126.  
  127. sub configure_item
  128. {
  129.     my ( $self, $name, $templ, $language ) = @_;
  130.  
  131.     if ( $name eq 'windows_trayicon_and_console' ) {
  132.         $templ->param( 'windows_icon_on' => $self->config_( 'trayicon' ) );
  133.         $templ->param( 'windows_console_on' => $self->config_( 'console' ) );
  134.     }
  135. }
  136.  
  137. # ---------------------------------------------------------------------------------------------
  138. #
  139. # validate_item
  140. #
  141. #    $name            The name of the item being configured, was passed in by the call
  142. #                     to register_configuration_item
  143. #    $templ           The loaded template
  144. #    $language        The language currently in use
  145. #    $form            Hash containing all form items
  146. #
  147. # ---------------------------------------------------------------------------------------------
  148.  
  149. sub validate_item
  150. {
  151.     my ( $self, $name, $templ, $language, $form ) = @_;
  152.  
  153.     if ( $name eq 'windows_trayicon_and_console' ) {
  154.  
  155.         if ( defined($$form{windows_trayicon}) ) {
  156.             $self->config_( 'trayicon', $$form{windows_trayicon} );
  157.             $templ->param( 'trayicon_feedback' => 1 );
  158.         }
  159.  
  160.         if ( defined($$form{windows_console}) ) {
  161.             $self->config_( 'console', $$form{windows_console} );
  162.             $templ->param( 'console_feedback' => 1 );
  163.         }
  164.     }
  165.  
  166.    return '';
  167. }
  168.  
  169. 1;
  170.